package qiniu;

import java.io.File;

import com.qiniu.api.auth.digest.Mac;
import com.qiniu.api.config.Config;
import com.qiniu.api.io.IoApi;
import com.qiniu.api.io.PutExtra;
import com.qiniu.api.io.PutRet;
import com.qiniu.api.rs.PutPolicy;

public class UploadFile {

    public static void main(String[] args) throws Exception {
        Config.ACCESS_KEY = "GKM5675OcKDvztgyMZ5khwBPcPdHEzL6nLVbnF-3";
        Config.SECRET_KEY = "4UdV81qqHgfRqr__CEdxCZ0OjcV-2ETL0jbMCqfi";
        Mac mac = new Mac(Config.ACCESS_KEY, Config.SECRET_KEY);
        // 请确保该bucket已经存在
        String bucketName = "tianhe";
        PutPolicy putPolicy = new PutPolicy(bucketName);
        String uptoken = putPolicy.token(mac);
        PutExtra extra = new PutExtra();
        String key = "logo";
        String localFile = "E:\\IdeaProjects14\\tianhe\\home\\src\\main\\webapp\\images\\logo.png";
        PutRet ret = IoApi.putFile(uptoken, key, localFile, extra);

        System.out.println(ret.getKey());
        System.out.println(ret.getResponse());
    }
}